/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.unifor.sd.bolsa.rmi;

import br.unifor.sd.bolsa.interfaces.RemoteListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Pedro
 */
public class ServidorRemoteImpl implements ServidorRemote {

    public ServidorRemoteImpl() {
        listeners = new ArrayList<RemoteListener>();
    }


    private List<RemoteListener> listeners;
    
    public void comprarAcao(Integer acao, String nomeComprador, Double valor) throws RemoteException {
        
    }

    public void iniciar(ClienteRemote cr) throws RemoteException {
        notificarTodos(cr);
    }

    private void notificarTodos(ClienteRemote cr){
        for(RemoteListener rl : listeners){
            rl.onMessage(cr);
        }
    }

    public void addListener(RemoteListener listener) throws RemoteException {
        listeners.add(listener);
    }
}
